<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 注意：项目正式环境请勿引用该地址 -->
    <link href="layui/css/layui.css" rel="stylesheet">
</head>
<body>


<script type="text/html" id="toolbarDemo">
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label" style="width: 110px;text-align: center">调拨日期</label>
            <div class="layui-inline layui-show-xs-block">
                <input class="layui-input" type="date"  autocomplete="off" placeholder="请选择日期" name="businessTime" id="businessTime">
            </div>
        </div>
        </div>
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label" style="width: 110px;text-align: center">调拨类型</label>
            <div class="layui-inline layui-show-xs-block" style="text-align: center" >
                <select name="allotType" id="allotType" >
                    <option value="" placeholder="请选择调拨类型"></option>
                    <option value="1">存款利息</option>
                    <option value="2">申购赎回清算款</option>
                    <option value="3">买卖交易清算款</option>
                    <option value="4">债券利息</option>
                    <option value="5">存款业务</option>
                    <option value="6">两费</option>
                </select>
            </div>
        </div>
        <div class="layui-inline layui-show-xs-block">
            <label class="layui-form-label" style="width: 110px;text-align: center">调拨方向</label>
            <div class="layui-inline layui-show-xs-block"  style="text-align: center">
                <select name="allotDirection" id="allotDirection">
                    <option value="" placeholder="请选择调拨方向"></option>
                    <option value="1">流入</option>
                    <option value="-1">流出</option>
                </select>
            </div>
        </div>
        <div class="layui-inline" style="height:29px;margin-right: 20px" title="搜索" lay-event="search"><i
                class="layui-icon layui-icon-search"></i></div>
    <button class="layui-btn layui-btn-sm" lay-event="insert" id="addUser" style="margin-right: 30px"><i
            class="layui-icon">&#xe654;</i>新增
    </button>
</script>
<script type="text/html" id="FundsAllot">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<!-- 注意：项目正式环境请勿引用该地址 -->
<script src="layui/layui.js"></script>


<script>
    layui.use('table', function () {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var layer = layui.layer;

        //温馨提示：默认由前端自动合计当前行数据。从 layui 2.5.6 开始： 若接口直接返回了合计行数据，则优先读取接口合计行数据。
        //详见：/docs/modules/table.html#totalRow
        table.render({
            height: 'full-55'
            , minLength: 80,
            elem: '#myTable'
            , id: 'tableId'
            , url: 'selectFundsAllot'
            , toolbar: '#toolbarDemo'
            , title: '资金调拨表'
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'fundsAllotId', title: '资产调拨ID',edit: 'text', fixed: 'left', unresize: true, sort: true, totalRowText: '合计',align:'center'}
                , {field: 'cashId', title: '现金账户', edit: 'text',align:'center'}
                , {field: 'fundId', title: '基金ID', edit: 'text',align:'center'}
                , {field: 'allotTypes', title: '调拨类型', edit: 'text',align:'center'}
                , {field: 'allotDirections', title: '调拨方向' , edit: 'int',align:'center'}
                , {field: 'allotMoney', title: '调拨金额', edit: 'int',align:'center'}
                , {field: 'businessId', title: '业务编号', edit: 'int',align:'center'}
                , {field: 'businessTime', title: '业务日期', edit: 'text',align:'center'}
                , {field: 'allotTime', title: '调拨日期', edit: 'text',align:'center'}
                , {field: 'allotRemark', title: '备注', edit: 'text',align:'center'}
                , {fixed: 'right', title: '操作', toolbar: '#FundsAllot',align:'center'}
            ]]
            , page: true
        });

        //工具栏事件
        table.on('toolbar(myTable2)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：' + data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选' : '未全选')
                    break;
            }
            ;

            if (obj.event == 'insert') {
                //点击按钮的时候，弹出一个添加页面
                layer.open({
                    type: 2,
                    title: "添加用户",
                    content: "addFundsAllot",
                    area:['60%','550px'],

                    //层销毁后触发
                    end: function () {
                        //刷新页面
                        table.reload('tableId');
                    }
                })
            }else if(obj.event=='search'){
                var businessTime=$("#businessTime").val();
                var allotDirection=$("#allotDirection").val();
                var allotType=$("#allotType").val();
                //表格的重新加载事件
                table.reload('tableId', {
                    method: 'post'
                    , where: {
                        'businessTime': businessTime,
                        'allotDirection': allotDirection,
                        'allotType': allotType,
                    }
                    , page: {
                        curr: 1
                    }
                });
                $("#businessTime").val(businessTime);
                $("#allotDirection").val(allotDirection);
                $("#allotType").val(allotType);
            }
        });

        table.on('tool(myTable2)', function (obj) {
            switch (obj.event) {
                case "del":
                    layer.confirm('您确定要删除吗', function (index) {
                        $.getJSON("deleteFundsAllot"
                            , {fundsAllotId: obj.data.fundsAllotId}
                            , function (msg) {
                                if (msg == 1) {
                                    layer.close(index)
                                    table.reload('fundsAllotId');
                                    setTimeout(function(){location.reload()},1);
                                }
                            })
                    })
                    break;
                case "edit":
                    alert(obj.data.allotTime);
                    layer.open({
                        type: 2,
                        title: "修改用户",
                        content: "updateFundsAllot",
                        area:['60%','550px'],
                        success:function (layero,index) {
                            var body = layer.getChildFrame('body',index);
                            body.find("#fundsAllotId").val(obj.data.fundsAllotId);
                            body.find("#cashId").val(obj.data.cashId);
                            body.find("#fundId").val(obj.data.fundId);
                            body.find("#allotType").val(obj.data.allotType);
                            body.find("#allotDirection").val(obj.data.allotDirection);
                            body.find("#allotMoney").val(obj.data.allotMoney);
                            body.find("#businessId").val(obj.data.businessId);
                            body.find("#businessTime").val(obj.data.businessTime);
                            body.find("#allotTime").val(obj.data.allotTime);
                            body.find("#allotRemark").val(obj.data.allotRemark);
                            body.find("#right").val(obj.data.right);
                        },
                        //层销毁后触发
                        end: function () {
                            //刷新页面
                            table.reload('tableId');
                            setTimeout(function(){location.reload()},1);
                        }
                    })
                    break;
            }
        })
    });
</script>
<table class="layui-hide" id="myTable" lay-filter="myTable2" ></table>
</body>
</html>